<template> 	
  <div class="page">
	<div class="layui-fluid">
			<div class="layui-row layui-col-space15">
				<div class="layui-col-md12">
					<div class="layui-card">
						
						<div class="layui-card-body">							
							<div class="layui-form" lay-filter="">																																												    						    						
								<div class="layui-form-item">
									<div class="layui-inline">
									    <label class="layui-form-label">更变选项</label>
									    <div class="layui-input-inline">
												<select name="aid" lay-filter="aid" v-model="aid">
													  <option value="1">更变推荐人</option>
													  <!--<option value="2">更换下级</option>-->
												</select>
											</div>											   
								  </div>
								</div>
								<div class="layui-form-item" >
									<div class="layui-inline">
									    <label class="layui-form-label">当前推荐人</label>
									    <div class="layui-input-inline" >
									        <input type="text" name="referrer" disabled="disabled" placeholder=""  v-model="itemData.introducer" autocomplete="off" class="layui-input" maxlength="">
									    </div>										   
								  </div>
								</div>
								<div class="layui-form-item" >
									<div class="layui-inline">
									    <label class="layui-form-label"></label>
									    <div class="layui-input-inline">
									        <input type="text" name="name" placeholder="请输入用户名或电话"  v-model="name" autocomplete="off" class="layui-input" maxlength="">
									    </div>
									    <div class="layui-form-mid layui-word-aux" @click="getss()">点击搜索</div>
								  </div>
								</div>
								<div class="layui-form-item" v-show="ispro==2" style="display:none">
									<div class="layui-inline" >
									    <label class="layui-form-label">更换后推荐人信息</label>
									    <div class="layui-input-block" style="width:150px;line-height:36px">姓名:{{gbData.name}}</div>											   
									    <div class="layui-input-block" style="width:150px;line-height:36px">昵称:{{gbData.nickName}}</div>											   
									    <div class="layui-input-block" style="width:150px;line-height:36px">手机号:{{gbData.mobile}}</div>											   
								  </div>
								</div>


								<div class="layui-form-item">
									<div class="layui-input-block">
										<button class="layui-btn layui-btn-normal" lay-submit lay-filter="setmyinfo" @click="confirmOk">确定</button>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>		
		<input type="hidden" id='id'/>
  </div> 
</template>
<script>
export default {	
  name: 'operatoradd',  
  data () {
    return { 
        id:'',
        aid:1,
    	ispro:1,
    	curindex:1, //页数 
    	itemData:{
            id:'',
            name:'',
            nickName:'',
            introducer:'',
            }, 
    	gbData:{
            id:'',
            name:'',
            mobile:'',
            nickName:''
            },
        accountId:'', 
        introducerId:'', 	
    	name:'',
    	fxsid:'',
  	}
  },
  mounted(){ 
  	var _this = this;   	
	  window.getdates = this.getdates;  
  },
  methods: {  	
		getdates:function(data){		
			var _this = this;
			_this.id=data.id;								
				var url="/account/bapi/v1.9/users/"+_this.id	
				ajaxRequest(url,'GET','json','',function(ret,err){
					if(ret.data){
					  _this.itemData=ret.data;
					  _this.accountId=ret.data.id;
					 }
				})

	  },
	  getss:function(){
	  	var _this=this;
	  	var name=_this.name;
	  	if(name){
	  		 _this.getgb();
		  } else {
			  layer.msg('输入的名称或电话号码不能为空');
	  		return false;
		  }
		//   alert(JSON.stringify(name))
	  },
	  getgb:function(){//id,accountName
          var _this=this;	 
          _this.ispro=2;	 		
			var url="/crm/aapi/v1.9/account/getUserByNameORMobile/" + _this.name
			ajaxRequest(url,'GET','json','',function(ret,err){
				// alert(url+"///"+JSON.stringify(ret))	
				// if()			 
				if(ret.data == null) {
					layer.msg('没有此用户');
	  		return false;
				}else{
				 _this.gbData=ret.data;
				 _this.introducerId=ret.data.id;
				}
			})
	  	
	  },
		confirmOk:function(){			
			var _this=this;				
			var len = $(".a").length;
			for(var i = 0; i < len; i++) {
				if($(".a").eq(i).val() == ''||$(".a").eq(i).val()<=0) {
					var msg = $(".a").eq(i).attr("placeholder");
					layer.msg('请输入正确的'+msg);
					return;
				}
			}	     
	    	if(_this.introducerId==''){
	      	  layer.msg("请选择更换后的推荐人");
						return;
	      }
	    	var url="/crm/aapi/v1.9/account/updateUserIntroducerByadmin"
	     	var dates={
	     		introducerId:_this.introducerId,	//用户		
					accountId:_this.accountId,	//现上级									
				}	     	

		 // alert(JSON.stringify(dates))				 
			ajaxRequest(url,'POST', 'JSON', dates, function(ret, err){
				//alert(JSON.stringify(dates)+"///"+JSON.stringify(ret))
				layer.msg('操作成功！');
				setTimeout(function(){
			  	var index = parent.layer.getFrameIndex(window.name);	          	
			    parent.layer.close(index);
		      parent.location.reload(); 
	      },1000)
			})
		},
  },
   updated:function(){
		this.isShow = true;
		var _this=this;
		layui.use('form', function(){
		  var form = layui.form;
		  form.render();
		});
  },

}
</script>
<style scoped>
.layui-form-label {
  width: 120px;
  font-size: 15px;
}
.layui-input-block {
  margin-left: 150px;
}
	.red{color:#ff0000;}
	.layuitj{float:left;line-height:38px;color:#FF0000;}
	.layuitj1{margin-left:20px;}
</style>
